package com.ct.gd.passport.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.widget.AdapterView.OnItemClickListener;
import com.ct.gd.passport.R;
import com.ct.gd.passport.common.BaseActivity;
import com.ct.gd.passport.common.constants.UmengVar;
import com.ct.gd.passport.domain.Helper;
import com.ct.gd.passport.view.discount.DiscountActivity;
import com.ct.gd.passport.view.exhibition.ExhibitionActivity;
import com.ct.gd.passport.view.ticket.TicketBookingActivity;
import com.ct.gd.passport.view.travel.ExchangeRateInfoActivity;
import com.ct.gd.passport.view.travel.MapTrafficActivity;
import com.ct.gd.passport.view.weather.WeatherServiceActivity;
import com.ct.gd.passport.view.widget.CustomHeaderFragment;
import com.umeng.analytics.MobclickAgent;
import com.umeng.update.UmengUpdateAgent;
import com.umeng.update.UmengUpdateListener;
import com.umeng.update.UpdateResponse;
import com.up91.common.android.view.adapter.SimpleListAdapter;

import java.util.ArrayList;
import java.util.List;

public class AboutActivity extends BaseActivity {

	private CustomHeaderFragment mFgHeader;

    @Override
	protected void onBaseCreate(Bundle savedInstanceState) {
		setContentView(R.layout.about);
	}

	@Override
	protected void initViews() {
		mFgHeader = (CustomHeaderFragment) getSupportFragmentManager()
				.findFragmentById(R.id.header);
        mFgHeader.setCenterText(R.string.about);
        TextView versionNameTv = (TextView)findViewById(R.id.tv_about_version);
        versionNameTv.setText("V"+getVersionName());
        Button mBtnCheck = (Button) findViewById(R.id.btn_check_update);
        mBtnCheck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UmengUpdateAgent.update(AboutActivity.this);
                UmengUpdateAgent.setUpdateAutoPopup(false);
                UmengUpdateAgent.setUpdateListener(new UmengUpdateListener() {
                    @Override
                    public void onUpdateReturned(int updateStatus,UpdateResponse updateInfo) {
                        switch (updateStatus) {
                            case 0: // has update
                                UmengUpdateAgent.showUpdateDialog(AboutActivity.this, updateInfo);
                                break;
                            case 1: // has no update
                                Toast.makeText(AboutActivity.this, "您使用的已是最新版本", Toast.LENGTH_SHORT)
                                        .show();
                                break;
                            case 2: // none wifi
                                Toast.makeText(AboutActivity.this, "没有wifi连接， 只在wifi下更新", Toast.LENGTH_SHORT)
                                        .show();
                                break;
                            case 3: // time out
                                Toast.makeText(AboutActivity.this, "超时", Toast.LENGTH_SHORT)
                                        .show();
                                break;
                        }
                    }
                });
            }
        });
	}

	@Override
	protected void onAfterCreate(Bundle savedInstanceStat) {
		super.onAfterCreate(savedInstanceStat);
	}

    private String getVersionName() {
        try {
            // 获取packagemanager的实例
            PackageManager packageManager = getPackageManager();
            // getPackageName()是你当前类的包名，0代表是获取版本信息
            PackageInfo packInfo = packageManager.getPackageInfo(getPackageName(),0);
            return packInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return "";
    }
}
